home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / xinfo101.lha / xinfo-1.01.01 / InfoP.h < prev    next >
C/C++ Source or Header  |  1991-01-09  |  9KB  |  326 lines

  1. #ifndef _InfoP_h
  2. #define _InfoP_h
  3.  
  4. /* $Header: /usr1/ben/jkh/tmp/xinfo/RCS/InfoP.h,v 1.4 91/01/07 14:02:11 jkh Exp Locker: jkh $ */
  5.  
  6. /*
  7.  *
  8.  *                   Copyright 1989, 1990
  9.  *                    Jordan K. Hubbard
  10.  *
  11.  *                PCS Computer Systeme, GmbH.
  12.  *                   Munich, West Germany
  13.  *
  14.  *
  15.  * This file is part of GNU Info widget.
  16.  *
  17.  * The GNU Info widget is free software; you can redistribute it and/or
  18.  * modify it under the terms of the GNU General Public License as published
  19.  * by the Free Software Foundation; either version 1, or (at your option)
  20.  * any later version.
  21.  *
  22.  * This software is distributed in the hope that it will be useful,
  23.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  25.  * GNU General Public License for more details.
  26.  *
  27.  * You should have received a copy of the GNU General Public License
  28.  * along with this software; see the file COPYING.  If not, write to
  29.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  30.  *
  31.  *
  32.  */
  33.  
  34. /*
  35.  * $Log:    InfoP.h,v $
  36.  * Revision 1.4  91/01/07  14:02:11  jkh
  37.  * Some naming changes.
  38.  * 
  39.  * Revision 1.3  90/11/12  18:07:21  jkh
  40.  * Added SET_BLOCK method for initializing text blocks.
  41.  * 
  42.  * Revision 1.2  90/11/11  22:24:27  jkh
  43.  * Added retain_arg
  44.  * 
  45.  * Revision 1.1  90/11/11  21:20:02  jkh
  46.  * Initial revision
  47.  * 
  48.  */
  49.  
  50. #include <X11/IntrinsicP.h>
  51. #include <X11/CoreP.h>
  52.  
  53. #include "Info.h"
  54.  
  55. /* max length of argument string */
  56. #define ARGLEN        128
  57.  
  58. /* max generic string size */
  59. #define MAXSTR        128
  60.  
  61. /* The largest we expect a note or menu name to get */
  62. #define MAXTOKEN    128
  63.  
  64. /* if no max pathlen, define arbitrarily */
  65. #ifndef MAXPATHLEN
  66. #define MAXPATHLEN    512
  67. #endif
  68.  
  69. /* More explanatory macro names */
  70. #define Export
  71. #define Import    extern
  72. #define Local    static
  73. #ifdef __GNUC__
  74. #define Inline __inline__
  75. #else
  76. #define Inline
  77. #endif
  78.  
  79. /* If we couldn't find it anywhere, make it up */
  80. #ifndef R_OK
  81. #define R_OK    04
  82. #endif
  83.  
  84. /* Convenience macro for setting text blocks */
  85. #define SET_BLOCK(blk, start, end, string) \
  86.     (blk).firstPos = (start), (blk).length = (end), \
  87.     (blk).ptr = (string), (blk).format = FMT8BIT
  88.  
  89. /* number of inits to bump tables up by during allocation */
  90. #define TABLE_INC    50
  91.  
  92. /* special INFO separator character */
  93. #define INFO_CHAR(ch)    ((ch) == '\000' || (ch) == '\037')
  94.  
  95. /* Delete char */
  96. #define DEL_CHAR    '\177'
  97.  
  98. /* Indirect start token */
  99. #define INDIRECT_TOKEN    "\037\nIndirect:\n"
  100.  
  101. /* Tag table start token */
  102. #define TAGTABLE_TOKEN    "\nTag Table:\n"
  103.  
  104. /* Indirect tag table token */
  105. #define ITAGTABLE_TOKEN    "(Indirect)\n"
  106.  
  107. /* Tag table end token */
  108. #define TAGEND_TOKEN    "\037\nEnd tag table\n"
  109.  
  110. /* Node header tokens */
  111. #define NODE_TOKEN    "Node: "
  112. #define PREV_TOKEN    "Prev: "
  113. #define NEXT_TOKEN    "Next: "
  114. #define UP_TOKEN    "Up: "
  115.  
  116. /* Menu start token */
  117. #define MENU_TOKEN    "\n* Menu:"
  118.  
  119. /* Menu seperator token */
  120. #define MENU_SEP_TOKEN    "\n* "
  121.  
  122. /* Footnote start token */
  123. #define NOTE_TOKEN    "*note"
  124.  
  125. /* End of a name */
  126. #define NAME_END_TOKEN    "\t\n,."
  127.  
  128. /* white space */
  129. #define WHITE        "\t\n\f "
  130.  
  131. /* delimiting characters that designate a node name */
  132. #define NAME        "\t\n,."
  133.  
  134. /* Table manipulation macros */
  135.  
  136. #define ZERO_TABLE(tab)                            \
  137.      (tab).size = (tab).idx = 0;                    \
  138.      (tab).table = (ID_P)NULL
  139.  
  140. #define FREE_TABLE(tab)                            \
  141.      if ((tab).table)                            \
  142.       XtFree((tab).table);                        \
  143.      ZERO_TABLE(tab)
  144.  
  145. #define ALLOC_TABLE(tab)                        \
  146.      FREE_TABLE(tab);                            \
  147.      (tab).size = TABLE_INC;                        \
  148.      (tab).idx = 0;                            \
  149.      (tab).table = (ID_P)XtMalloc(sizeof(ID) * TABLE_INC)
  150.  
  151. #define MAYBE_BUMP_TABLE(tab)                        \
  152.      (((tab).idx == (tab).size) ? (tab).size += TABLE_INC,        \
  153.       (tab).table = (ID_P)XtRealloc((tab).table, (tab).size *        \
  154.                     sizeof(ID)), 1 : 0)
  155.  
  156. #define ROUND_TABLE(tab)                        \
  157.      ((tab).table[(tab).idx].tag.name = NULL,                \
  158.       (tab).table[(tab).idx].offset.length = 0,                \
  159.       ((tab).idx + 1 != (tab).size) ? (tab).size = (tab).idx + 1,    \
  160.       (tab).table = (ID_P)XtRealloc((tab).table, (tab).size *        \
  161.                     sizeof(ID)), 1 : 0)
  162.  
  163. #define ZERO_LIST(lst)                            \
  164.      ZERO_TABLE((lst).t);                        \
  165.      (lst).l = (Strings)NULL
  166.  
  167. #define FREE_LIST(lst)                            \
  168.      FREE_TABLE((lst).t);                        \
  169.      if ((lst).l) {                            \
  170.       Strings lp = (lst).l;                        \
  171.       while (*lp)                            \
  172.            XtFree(*(lp++));                        \
  173.       XtFree((lst).l);                        \
  174.       (lst).l = (Strings)NULL;                    \
  175.      }
  176.  
  177. #define ALLOC_LIST(lst)                            \
  178.      ALLOC_TABLE((lst).t);                        \
  179.      (lst).l = (Strings)XtMalloc(sizeof(String) * TABLE_INC)
  180.  
  181. #define FREE_TAG_TABLE(tab)                        \
  182.      {                                    \
  183.      int i;                                \
  184.      for (i = 0; i < IDX((tab)); i++)                     \
  185.           XtFree(I_NAME((tab).table[i]));                 \
  186.      XtFree((tab).table);                        \
  187.      (tab).table = NULL;                        \
  188.      }
  189.  
  190. #define MAYBE_BUMP_LIST(lst)                        \
  191.      if (MAYBE_BUMP_TABLE((lst).t))                    \
  192.      (lst).l = (Strings)XtRealloc((lst).l, (lst).t.size *        \
  193.                       sizeof(String));            \
  194.  
  195. #define ROUND_LIST(lst)                            \
  196.      if (ROUND_TABLE((lst).t))                        \
  197.      (lst).l = (Strings)XtRealloc((lst).l, (lst).t.size *        \
  198.                       sizeof(String));            \
  199.      (lst).l[(lst).t.idx] = NULL
  200.  
  201. #define IDX(tab)    ((tab).idx)
  202. #define TPOS(tab)    ((tab).table[IDX(tab)])
  203. #define LPOS(lst)    ((lst).l[IDX((lst).t)])
  204. #define INCP(tab)    (IDX(tab)++)
  205.  
  206. /* Turn address s into ptr relative index */
  207. #define INTOFF(ptr, s)        ((int)((s) - (ptr)))
  208.  
  209. typedef String *Strings;
  210.      
  211. typedef struct {
  212.      int nichts;
  213. } InfoClassPart;
  214.  
  215. typedef struct _InfoClassRec {
  216.      CoreClassPart        core_class;
  217.      CompositeClassPart        composite_class;
  218.      InfoClassPart        info_class;
  219. } InfoClassRec;
  220.  
  221. extern InfoClassRec infoClassRec;
  222.  
  223. /* A generic ID (tag/offset). */
  224. typedef union _id {
  225.      struct {                /* if it's a tag        */
  226.       String name;
  227.       int offset;
  228.      } tag;
  229.      struct {                /* if it's an offset        */
  230.       int start;
  231.       int length;
  232.      } offset;
  233. } ID, *ID_P;
  234.  
  235. /* An array of ID's */
  236. typedef struct _table {
  237.      int idx;                /* where we are in the table    */
  238.      int size;
  239.      ID_P table;
  240. } Table;
  241.  
  242. /* a special string/ID associative table */
  243. typedef struct _idlist {
  244.      Table t;                /* ID array representation    */
  245.      Strings l;                /* string array representation    */
  246. } IDList;
  247.  
  248. /* everything we'd like to know about a node */
  249. typedef struct _nodeinfo {
  250.      String file;            /* node's file name        */
  251.      String node;            /* node's nodename        */
  252.      int start;                /* starting position        */
  253.      int length;            /* length of node        */
  254.      ID name;                /* location of nodename        */
  255.      ID prev, up, next;            /* locations of prev, up, next    */
  256.      ID text;                /* location of text        */
  257.      IDList menu;            /* menu information        */
  258.      IDList xref;            /* cross references        */
  259.      struct _nodeinfo *nextNode;    /* for history list        */
  260. } NodeInfo;
  261.  
  262. typedef struct {
  263.      /* resources */
  264.      String path;            /* search path            */
  265.      String file;            /* current info file        */
  266.      String node;            /* current node name        */
  267.      String printCmd;            /* lpr command            */
  268.      int bell_volume;            /* bell volume for error feeps    */
  269.      Boolean retain_arg;        /* whether or not to save arg    */
  270.      XtCallbackList callback;        /* quit callback        */
  271.  
  272.      /* private state */
  273.      String subFile;            /* current split file (if any)    */
  274.      NodeInfo *history;            /* the history list        */
  275.      Table indirect;            /* indirect files        */
  276.      Table tags;            /* indirect tags        */
  277.      String data;            /* pointer to file contents    */
  278.      int size;                /* size of file contents    */
  279.      int hdrSize;            /* size of file header        */
  280.      char arg[ARGLEN];            /* command argument string    */
  281.      Widget fileLabel, nodeLabel;    /* file and node labels        */
  282.      Widget prevCmd, upCmd, nextCmd;    /* prev, up and next commands    */
  283.      Widget menuList;            /* menu list            */
  284.      Widget xrefList;            /* xref list            */
  285.      Widget nodeText;            /* node text            */
  286.      Widget statusLabel;        /* status area            */
  287.      Widget messageLabel;        /* message area            */
  288.      Widget xrefCmd, gotoCmd, searchCmd;/* xref, goto and search cmds    */
  289.      Widget argText;            /* xref/goto/search arg text    */
  290.      Widget helpPopup;            /* help popup            */
  291.      Widget argPopup;            /* argument popup        */
  292.      void (*requester)();        /* routine asking for argument    */
  293. } InfoPart;
  294.  
  295. typedef struct _InfoRec {
  296.      CorePart        core;
  297.      CompositePart    composite;
  298.      InfoPart        info;
  299. } InfoRec;
  300.  
  301. /* special accessors for info widget */
  302. #define DATA(iw)        ((iw)->info.data)
  303. #define DATASIZE(iw)        ((iw)->info.size)
  304. #define HDRSIZE(iw)        ((iw)->info.hdrSize)
  305. #define INDIRECT(iw)        ((iw)->info.indirect)
  306. #define TAGTABLE(iw)        ((iw)->info.tags)
  307. #define HISTORY(iw)        ((iw)->info.history)
  308.  
  309. /* misc */
  310. #define CURNODE(iw)        HISTORY(iw)
  311.  
  312. /* for search */
  313. #define START(iw)        (DATA(iw))
  314. #define END(iw)            (START(iw) + DATASIZE(iw))
  315. #define NSTART(iw, n)        (START(iw) + (n)->start)
  316. #define NEND(iw, n)        (NSTART(iw, n) + (n)->length)
  317. #define NSEARCH(iw, n, str)    (search(iw,NSTART(iw,n),NEND(iw,n),str,False))
  318.  
  319. /* for id's */
  320. #define I_NAME(i)        ((i).tag.name)
  321. #define I_OFFSET(i)        ((i).tag.offset)
  322. #define I_START(i)        ((i).offset.start)
  323. #define I_LEN(i)        ((i).offset.length)
  324.  
  325. #endif /* _InfoP_h */
  326.